package q24_swapPairs;
import static CommonClass.Common.*;


public class Solution {
    public static void main(String[] args) {
        ListNode listNode = generateList(new int[]{1,2,3,4,5});
        printList(swapPairs(listNode));
    }

    public static ListNode swapPairs(ListNode head) {
        if (head == null || head.next == null) {
            return head;
        }
        ListNode res = head.next;

        if (res.next != null) {
            head.next = swapPairs(head.next.next);
        } else {
            head.next = null;
        }

        res.next = head;
        return res;
    }

}
